package com.tarena.day030;
import java.util.Scanner;
/** 分支条件判断 */
public class IfElseDemo {
  public static void main(String[] args) {
    Scanner console = new Scanner(System.in);
    int qty;
    while(true){
      System.out.print("输入购买数量:");
      qty = console.nextInt();
      if(qty>0){
        break;//结束当前循环
      }
      System.out.println("坑跌呀!"); 
    }
    
    System.out.println("金额:"+count(qty, 5));
  }
  /** 计算商品支付价格: 第二杯半价, 参数:qty数量,price:单价 */
  public static double count(int qty, int price){
    double pay = qty/2*price + qty/2*(price/2D);
    if(qty%2!=0){
      pay+=price; //pay = pay + price;//与pay+=price等价
    }
//    double pay=0;
//    if(qty%2==0){//购买了2的倍数
//      pay = qty/2 * price + qty/2*(price/2D);
//    }else{
//      pay = qty/2 * price + qty/2*(price/2D) + price;
//    }
    return pay;
  }
  
}




